package com.training.java.redbox.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.training.java.redbox.domain.DAOException;
import com.training.java.redbox.domain.Inventory;
import com.training.java.redbox.domain.InventoryDAO;
import com.training.java.redbox.domain.InventoryDAOJDBCImpl;

/**
 * Servlet implementation class InventoryServlet
 */
public class InventoryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		List<Inventory> inventories = null;
		System.out.println("working");
				
			InventoryDAO dao = new InventoryDAOJDBCImpl();	
			try {
				 inventories = dao.getAllInventory();
			} catch (DAOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			for(Inventory inventory : inventories){
				System.out.println(inventory.getCount());
				
			}
			request.setAttribute("Inventories", inventories);
			RequestDispatcher rd = request.getRequestDispatcher("/listmovies");
			rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
